package com.cd.card.controller;

import com.cd.common.annotation.Log;
import com.cd.common.controller.BaseController;
import com.cd.common.domain.AjaxResult;
import com.cd.common.enums.BusinessType;
import com.cd.common.util.TableDataInfo;
import com.cd.card.domain.LqqCard;
import com.cd.card.service.CardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/card")
public class CardController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(CardController.class);

    @Autowired
    private CardService cardService;

    @GetMapping("/list")
    public TableDataInfo getCardList(LqqCard lqqCard) {
        startPage();
        List<LqqCard> list = cardService.getAllCardList(lqqCard);
        return getDataTable(list);
    }
    //抽卡系统，若初次抽卡，创建抽卡信息并更新大保底conut
    //后续可增加抽别人卡的玩法

    /**
     * @Description num是抽卡次数，mode是抽卡类型，0是普通，1是限定，2是超欧模式
     * @Author lqq
     * @Date 2024/6/24 17:42
     **/
    @PostMapping("/draw")
    @Log(title = "抽卡", businessType = BusinessType.DRAW)
    public AjaxResult drawCard(Long num, String mode) {
        Map<String, Object> result = cardService.drawCard(num, mode);
        return success(result);
        //return success(list.stream().map(LqqCard::getCardName).collect(Collectors.toList()));
    }

    @GetMapping("/userInfo")
    public AjaxResult getCardUserInfo() {
        return success(cardService.getCardUserInfo());
    }

    @GetMapping("/getRankList")
    public AjaxResult getRankList() {
        return success(cardService.getRankList());
    }

    //获取记录
    @GetMapping("/getRecord")
    public AjaxResult getRecord() {
        return success(cardService.getRecord());
    }

    @GetMapping("/getInventory")
    public AjaxResult getCard() {
        return success(cardService.getInventory());
    }

    @GetMapping("/clearHistory")
    public AjaxResult clearHistory() {
        return success(cardService.clearHistory());
    }
}
